//
//  CBar.cpp
//  beast_tamer
//
//  Created by chiawei.tseng on 13/2/19.
//
//

#include "CBar.h"
#include "CObject.h"

CBar* CBar::CreateBar(const char *spName , const fPoint &point ,CObject* Master ,BARTYPE BarType)
{
    CBar *ptr = new CBar();
    
    if (ptr && ptr->initWithFile(spName) && ptr->init())
    {
        ptr->InitWithData(point , Master , BarType);
        ptr->autorelease();
        
        return ptr;
    }
    
    CC_SAFE_DELETE(ptr);
    
    return NULL;
}

CBar::CBar()
{
    
}

CBar::~CBar()
{
    
}

void CBar::InitWithData(const fPoint &point ,CObject* Master ,BARTYPE BarType)
{
    setPosition(ccp(point.X,point.Y));
    
    setAnchorPoint(ccp(0, 0));
    
    m_Master = Master;
    m_BarType = BarType;
}

bool CBar::init()
{
    if(!CBaseUI::init())
        return false;
    
    m_UiType = UI_BAR;
    
    return true;
}

void CBar::update()
{
    if (!m_Master)
        return;
    
    
    switch (m_BarType)
    {
        case HP_BAR_TYPE:
            float fScaleX = (float)(m_Master->GetHP() / m_Master->GetMaxHP());
            setScaleX(fScaleX);
            break;
        
    }
    
}